import 'package:flutter/material.dart';
import 'package:hello_world/layout-i.dart';
import 'package:hello_world/views/login.dart';
// import 'package:hello_world/home.dart';
import 'package:hello_world/bus.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

// https://blog.csdn.net/believeinbelieve/article/details/88928476

class _MyAppState extends State<MyApp> {
  BuildContext _context;
  @override
  Widget build(BuildContext context) {
    // this._context = context;
    return new MaterialApp(
      title: 'Navigation',
      // initialRoute: '/',
      home: LayoutI(),
      routes: <String, WidgetBuilder>{
        // '/': (BuildContext context) => new LayoutI(),
        '/layout-i': (BuildContext context) => new LayoutI(),
        // '/home': (BuildContext context) => new Home(),
        '/login': (BuildContext context) => new Login(),
      },
    );
  }
  @override
  void initState() {
    super.initState();
    bus.on("set_context", (arg) {
      this._context = arg;
    });
    bus.on("login", (arg) {
      print(arg);
      Navigator.pushNamed(this._context, '/login'); 
    });
    print('initState');
  }
}
